package kit.edu.lego.gruppe3.levels.labyrinth;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSolver;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;

public class LabyrinthSolver implements LevelSolver
{
	
	public LabyrinthSolver()
	{
	}


	@Override
	public void start()
	{
		LevelSelector.getInstance().setCurrentLevel(Level.labyrinth);
		
			Behavior labyrinthEnd = new LabyrinthEndReached();
			Behavior findRightSide = new FindRightWall();
			Behavior moveParallel = new MoveParallelToWall();
			Behavior hitFrontWall = new HitFrontWall();
			
			Behavior[] behaviors = {moveParallel, findRightSide, hitFrontWall, labyrinthEnd};
			Arbitrator arby = new Arbitrator(behaviors);
			
			ComponentsRepository.getInstance().getMiddleMotor().stop(false);
			
			arby.start();
	
	}
	
	@Override
	public String toString()
	{
		return "Labyrinth solver";
	}
	
	private static boolean levelCleared = false;
	
	public static boolean isLevelCleared()
	{
		return levelCleared;
	}
	
	public static void setLevelCleared(boolean cleared)
	{
		levelCleared = cleared;
	}
	
	

}
